<?php

function getAllInformations($BDD_connexion,$locationId) {
	
	$datas = array();
	
	$requestLocation = "SELECT * FROM location WHERE id_location = :id_location";
	$prepareLocation = $BDD_connexion->prepare($requestLocation);
	$prepareLocation->bindValue(':id_location',$locationId,PDO::PARAM_INT);
	$prepareLocation->execute();
	$location = $prepareLocation->fetch(PDO::FETCH_OBJ);
	
	$requestGood = "SELECT * FROM bien WHERE id_bien = :id_bien";
	$prepareGood = $BDD_connexion->prepare($requestGood);
	$prepareGood->bindValue(':id_bien',$location->ref_bien,PDO::PARAM_INT);
	$prepareGood->execute();
	$good = $prepareGood->fetch(PDO::FETCH_OBJ);
	
	$requestOwner = "SELECT * FROM personne,location WHERE location.id_location = :id_location AND personne.id = (SELECT ref_proprio FROM bien WHERE bien.id_bien = location.ref_bien)";
	$prepareOwner = $BDD_connexion->prepare($requestOwner);
	$prepareOwner->bindValue(':id_location',$locationId,PDO::PARAM_INT);
	$prepareOwner->execute();
	$owner = $prepareOwner->fetch(PDO::FETCH_OBJ);
	
	$requestOwnerAddress = "SELECT * FROM adresse WHERE id_adresse = :id_adresseproprio";
	$prepareOwnerAddress = $BDD_connexion->prepare($requestOwnerAddress);
	$prepareOwnerAddress->bindValue(':id_adresseproprio',$owner->ref_adresse,PDO::PARAM_INT);
	$prepareOwnerAddress->execute();
	$ownerAddress = $prepareOwnerAddress->fetch(PDO::FETCH_OBJ);
	
	$owner->address = $ownerAddress;
	
	$requestClient = "SELECT * FROM personne,location WHERE personne.id = location.ref_personne AND location.id_location = :id_location";
	$prepareClient = $BDD_connexion->prepare($requestClient);
	$prepareClient->bindValue(':id_location',$locationId,PDO::PARAM_INT);
	$prepareClient->execute();
	$client = $prepareClient->fetch(PDO::FETCH_OBJ);
	
	$requestClientAddress = "SELECT * FROM adresse WHERE id_adresse = :id_adresseclient";
	$prepareClientAddress = $BDD_connexion->prepare($requestClientAddress);
	$prepareClientAddress->bindValue(':id_adresseclient',$client->ref_adresse,PDO::PARAM_INT);
	$prepareClientAddress->execute();
	$clientAddress = $prepareClientAddress->fetch(PDO::FETCH_OBJ);
	
	$client->address = $clientAddress;
	
	$requestAddress = "SELECT * FROM adresse WHERE id_adresse = :id_adresse";
	$prepareAddress = $BDD_connexion->prepare($requestAddress);
	$prepareAddress->bindValue(':id_adresse',$good->ref_adresse,PDO::PARAM_INT);
	$prepareAddress->execute();
	$address = $prepareAddress->fetch(PDO::FETCH_OBJ);
	
	$requestDescription = "SELECT content FROM descriptions WHERE id_langue = :id_langue AND id_bien = :id_bien";
	$prepareDescription = $BDD_connexion->prepare($requestDescription);
	$prepareDescription->bindValue(':id_langue',$_SESSION['langid'],PDO::PARAM_INT);
	$prepareDescription->bindValue(':id_bien',$location->ref_bien,PDO::PARAM_INT);
	$prepareDescription->execute();
	$description = $prepareDescription->fetch(PDO::FETCH_OBJ);
	
	$location->description = $description->content;
	
	$datas["location"] = $location;
	$datas["good"] = $good;
	$datas["owner"] = $owner;
	$datas["client"] = $client;
	$datas["address"] = $address;
		
	return $datas;
	
}

?>
